import { useFlyNumStore } from '@/stores/modules/flynum'
const flyNumStore = useFlyNumStore()

export const addObjMove = async () => {
  await clear()
  // 大梅沙
  addCusObjectDa(ppList)
  cusObjectDaMove(ppList, 15)
  addLine(ppList, [0, 1, 1, 1])

  // 恩上
  addCusObjectDa(enList)
  cusObjectDaMove(enList, 40)
  addLine(enList, [0, 1, 1, 1])

  //更新标签内容
  updateMarkerText()
}

/**
 * 大梅沙直升机坐标
 */
export const peopleList = [
  {
    id: '直升机1',
    coor: [
      [531603.015938, 2500106.38125, 1300.67125],
      [531280.33625, 2499704.048125, 1300],
      [531219.945313, 2499462.48375, 1300],
      [531280.335625, 2499059.88125, 1300.9975],
      [531553.709688, 2498829.251875, 1300.99875],
      [531951.344219, 2498670.1975, 1300.00125],
      [532686.9675, 2498829.251875, 1300.9975],
      [533362.94625, 2499226.88625, 1300.9975],
      [533879.870625, 2499624.520625, 1300],
      [534158.215156, 2500022.155625, 1300.99875],
      [534078.688125, 2500499.318125, 1300],
      [533672.821016, 2500908.798125, 1300.68875],
      [533152.448516, 2500509.2575, 1300],
      [533024.957031, 2499942.629375, 1300.99875],
      [532546.675469, 2500016.181875, 1300.00125],
      [532293.065156, 2500406.354375, 1300.90125],
      [531805.302813, 2500172.286875, 1300.00125]
    ],
    jd: 80,
    name: '直升机1',
    imagePath: window.origin + `/poi/poi_门禁@2x.png`,
    popupURL:
      window.origin +
      '/popup/zhishenji.html?parmas=' +
      encodeURIComponent(
        JSON.stringify({
          id: '直升机1',
          name: '罗宾逊R44'
        })
      ),
    assetPath: '/JC_CustomAssets/ObjectLibrary/Exhibition/交通工具/飞机/直升机_1',
    groupId1: 'CusObjectDaGroup',
    groupId2: 'CusObjectDaMarker'
  }
]


/**
 * 恩上公园
 */
export const enList = [
  {
    id: 'evtol2',
    coor: [
      [523668.4825, 2497082.112812, 1300.931797],
      [523574.562246, 2497103.816562, 1300.896797],
      [523494.224004, 2497161.726875, 1300.086172],
      [523510.039121, 2497242.798437, 1300.775781],
      [523580.682422, 2497318.126875, 1300.376641],
      [523738.356523, 2497410.34625, 1300.496406],
      [523873.562578, 2497459.905625, 1300.146406],
      [523999.436445, 2497423.345312, 1300.633438],
      [524041.091875, 2497370.583125, 1300.671719],
      [524020.491797, 2497297.199688, 1300.780469],
      [523937.090742, 2497205.99125, 1300.646563],
      [523796.229766, 2497124.436875, 1300.765781],
      [523681.382148, 2497078.680625, 1300.317891]
    ],
    jd: 270,
    name: 'evtol2',
    imagePath: window.origin + `/poi/poi_人员@2x.png`,
    popupURL:
      window.origin +
      '/popup/zhishenji.html?parmas=' +
      encodeURIComponent(
        JSON.stringify({
          id: 'evtol2',
          name: '亿航216s'
        })
      ),
    assetPath: '/JC_CustomAssets/ObjectLibrary/Exhibition/盐田低空无人机/无人机3',
    groupId1: 'EvtolObjectDaGroup',
    groupId2: 'EvtolObjectDaMarker'
  }
]

/**
 * 东部华侨城
 */
export const sList = [
  {
    id: '直升机2',
    coor: [
      [527027.919687, 2503010.039375, 1000.049219],
      [526836.782188, 2503010.816562, 1000.099531],
      [526645.06125, 2502908.419375, 1000.248438],
      [526517.414687, 2502780.005, 1000.080156],
      [526406.829063, 2502563.626719, 1000.711094],
      [526337.902813, 2502400.11375, 1000.774844],
      [526443.245, 2502274.123438, 1000.57375],
      [526709.701875, 2502202.578125, 1000.454844],
      [526952.077187, 2502235.616875, 1000.890156],
      [527099.630938, 2502333.076719, 1000.067656],
      [527154.901563, 2502508.513281, 1000.527812],
      [527148.205937, 2502626.296406, 1000.307656],
      [527110.303438, 2502796.010625, 1000.24375],
      [527051.735, 2502970.011875, 1000.852031]
    ],
    jd: 90,
    name: '直升机2',
    imagePath: window.origin + `/poi/poi_门禁@2x.png`,

    popupURL:
      window.origin +
      '/popup/zhishenji.html?parmas=' +
      encodeURIComponent(
        JSON.stringify({
          id: '直升机2',
          name: '罗宾逊R44'
        })
      ),
    assetPath: '/JC_CustomAssets/ObjectLibrary/Exhibition/交通工具/飞机/直升机_1',
    groupId1: 'CusObjectDaGroup',
    groupId2: 'CusObjectDaMarker'
  }
]

// 无人机
export const navList = [
  {
    id: '无人机xz1',
    coor: [
      [531603.015938, 2500106.38125, 1300.67125],
      [531280.33625, 2499704.048125, 1300],
      [531219.945313, 2499462.48375, 1300],
      [531280.335625, 2499059.88125, 1300.9975],
      [531553.709688, 2498829.251875, 1300.99875],
      [531951.344219, 2498670.1975, 1300.00125],
      [532686.9675, 2498829.251875, 1300.9975],
      [533362.94625, 2499226.88625, 1300.9975],
      [533879.870625, 2499624.520625, 1300],
      [534158.215156, 2500022.155625, 1300.99875],
      [534078.688125, 2500499.318125, 1300],
      [533672.821016, 2500908.798125, 1300.68875],
      [533152.448516, 2500509.2575, 1300],
      [533024.957031, 2499942.629375, 1300.99875],
      [532546.675469, 2500016.181875, 1300.00125],
      [532293.065156, 2500406.354375, 1300.90125],
      [531805.302813, 2500172.286875, 1300.00125]
    ],
    jd: 80,
    name: '无人机xz1',
    imagePath: window.origin + `/poi/qjss_lenged_05.png`,
    popupURL:
      window.origin +
      '/popup/zhishenji.html?parmas=' +
      encodeURIComponent(
        JSON.stringify({
          id: '无人机xz1',
          name: '无人机xz1R44'
        })
      ),
    assetPath: '/JC_CustomAssets/ObjectLibrary/Exhibition/交通工具/飞机/直升机_1',
    groupId1: 'CusObjectDaGroup',
    groupId2: 'CusObjectDaMarker'
  }
]

// 无人机2
export const navList2 = [
  {
    id: '无人机xz2',
    coor: [
      [527027.919687, 2503010.039375, 1000.049219],
      [526836.782188, 2503010.816562, 1000.099531],
      [526645.06125, 2502908.419375, 1000.248438],
      [526517.414687, 2502780.005, 1000.080156],
      [526406.829063, 2502563.626719, 1000.711094],
      [526337.902813, 2502400.11375, 1000.774844],
      [526443.245, 2502274.123438, 1000.57375],
      [526709.701875, 2502202.578125, 1000.454844],
      [526952.077187, 2502235.616875, 1000.890156],
      [527099.630938, 2502333.076719, 1000.067656],
      [527154.901563, 2502508.513281, 1000.527812],
      [527148.205937, 2502626.296406, 1000.307656],
      [527110.303438, 2502796.010625, 1000.24375],
      [527051.735, 2502970.011875, 1000.852031]
    ],
    jd: 80,
    name: '无人机xz2',
    imagePath: window.origin + `/poi/qjss_lenged_05.png`,
    popupURL:
      window.origin +
      '/popup/zhishenji.html?parmas=' +
      encodeURIComponent(
        JSON.stringify({
          id: '无人机xz2',
          name: '无人机xz1R442'
        })
      ),
    assetPath: '/JC_CustomAssets/ObjectLibrary/Exhibition/交通工具/飞机/直升机_1',
    groupId1: 'CusObjectDaGroup',
    groupId2: 'CusObjectDaMarker'
  }
]

// 民航客机
export const mhkj = [
  {
    id: '民航客机xz1',
    coor: [
      [531603.015938, 2500106.38125, 1300.67125],
      [531280.33625, 2499704.048125, 1300],
      [531219.945313, 2499462.48375, 1300],
      [531280.335625, 2499059.88125, 1300.9975],
      [531553.709688, 2498829.251875, 1300.99875],
      [531951.344219, 2498670.1975, 1300.00125],
      [532686.9675, 2498829.251875, 1300.9975],
      [533362.94625, 2499226.88625, 1300.9975],
      [533879.870625, 2499624.520625, 1300],
      [534158.215156, 2500022.155625, 1300.99875],
      [534078.688125, 2500499.318125, 1300],
      [533672.821016, 2500908.798125, 1300.68875],
      [533152.448516, 2500509.2575, 1300],
      [533024.957031, 2499942.629375, 1300.99875],
      [532546.675469, 2500016.181875, 1300.00125],
      [532293.065156, 2500406.354375, 1300.90125],
      [531805.302813, 2500172.286875, 1300.00125]
    ],
    jd: 80,
    name: '民航客机xz1',
    imagePath: window.origin + `/poi/民航客机.png`,
    popupURL:
      window.origin +
      '/popup/zhishenji.html?parmas=' +
      encodeURIComponent(
        JSON.stringify({
          id: '民航客机xz1',
          name: '民航客机xz1R44'
        })
      ),
    assetPath: '/JC_CustomAssets/ObjectLibrary/Exhibition/交通工具/飞机/直升机_1',
    groupId1: 'CusObjectDaGroup',
    groupId2: 'CusObjectDaMarker'
  }
]

// 民航客机2
export const mhkj2 = [
  {
    id: '民航客机xz2',
    coor: [
      [527027.919687, 2503010.039375, 1000.049219],
      [526836.782188, 2503010.816562, 1000.099531],
      [526645.06125, 2502908.419375, 1000.248438],
      [526517.414687, 2502780.005, 1000.080156],
      [526406.829063, 2502563.626719, 1000.711094],
      [526337.902813, 2502400.11375, 1000.774844],
      [526443.245, 2502274.123438, 1000.57375],
      [526709.701875, 2502202.578125, 1000.454844],
      [526952.077187, 2502235.616875, 1000.890156],
      [527099.630938, 2502333.076719, 1000.067656],
      [527154.901563, 2502508.513281, 1000.527812],
      [527148.205937, 2502626.296406, 1000.307656],
      [527110.303438, 2502796.010625, 1000.24375],
      [527051.735, 2502970.011875, 1000.852031]
    ],
    jd: 80,
    name: '民航客机xz2',
    imagePath: window.origin + `/poi/民航客机.png`,
    popupURL:
      window.origin +
      '/popup/zhishenji.html?parmas=' +
      encodeURIComponent(
        JSON.stringify({
          id: '无人机xz2',
          name: '无人机xz1R442'
        })
      ),
    assetPath: '/JC_CustomAssets/ObjectLibrary/Exhibition/交通工具/飞机/直升机_1',
    groupId1: 'CusObjectDaGroup',
    groupId2: 'CusObjectDaMarker'
  }
]


/**
 * 大梅沙evtol坐标
 */
export const ppList = [
  {
    id: 'evtol1',
    coor: [
      [532123.660625, 2500415.103125, 400.636875],
      [532219.80125, 2500294.689375, 400.999688],
      [532320.924375, 2500107.1625, 400.999688],
      [532311.78375, 2499955.05125, 400.999688],
      [532175.026875, 2499774.37375, 400],
      [531960.01, 2499741.488125, 400.999688],
      [531750.128125, 2499813.33875, 400],
      [531766.8975, 2500055.22125, 400],
      [531914.365625, 2500181.6225, 400],
      [532043.991875, 2500262.66625, 400.999688],
      [532120.326875, 2500440.51125, 400]
    ],
    jd: 270,
    name: 'evtol1',
    imagePath: window.origin + `/poi/poi_人员@2x.png`,
    popupURL:
      window.origin +
      '/popup/zhishenji.html?parmas=' +
      encodeURIComponent(
        JSON.stringify({
          id: 'evtol1',
          name: '亿航216s'
        })
      ),
    assetPath: '/JC_CustomAssets/ObjectLibrary/Exhibition/盐田低空无人机/无人机3',
    groupId1: 'EvtolObjectDaGroup',
    groupId2: 'EvtolObjectDaMarker'
  }
]

/**
 * 大梅沙滑翔伞坐标
 */
export const pList = [
  {
    id: '滑翔伞1',
    coor: [
      [531419.02125, 2499978.440625, 500.9025],
      [531352.039375, 2499725.804375, 500],
      [531439.09, 2499320.170625, 500],
      [531593.768125, 2498966.340625, 500.999375],
      [531990.103125, 2498776.219375, 500.000625],
      [532416.365625, 2498846.339375, 500.999375],
      [532641.456875, 2499098.8275, 500],
      [532619.55375, 2499325.951875, 500],
      [532420.030625, 2499529.700625, 500],
      [532048.1375, 2499775.664375, 500.999375],
      [531725.59625, 2499883.093125, 500.999375],
      [531487.001875, 2499975.910625, 500.435625]
    ],
    jd: 30,
    name: '滑翔伞1',
    imagePath: window.origin + `/poi/qjss_lenged_01.png`,
    popupURL:
      window.origin +
      '/popup/zhishenji.html?parmas=' +
      encodeURIComponent(
        JSON.stringify({
          id: '滑翔伞1',
          name: '滑翔伞'
        })
      ),
    assetPath: '/JC_CustomAssets/ObjectLibrary/Exhibition/滑翔伞/滑翔伞带人',
    groupId1: 'HuaObjectDaGroup',
    groupId2: 'HuaObjectDaMarker'
  },
  {
    id: '滑翔伞2',
    coor: [
      [531092.642188, 2499574.8275, 500.99875],
      [531257.822344, 2499178.394375, 500.999375],
      [532015.448281, 2499003.388125, 500],
      [532169.202656, 2499303.105625, 500.99875],
      [532568.835234, 2499564.090625, 500.999375],
      [532669.925156, 2499705.79625, 500.31125],
      [532355.14, 2499873.103125, 500.400625],
      [531687.441094, 2499874.626875, 500.999375],
      [531194.19375, 2499786.19875, 500.870625]
    ],
    jd: 15,
    name: '滑翔伞2',
    imagePath: window.origin + `/poi/qjss_lenged_01.png`,
    popupURL:
      window.origin +
      '/popup/zhishenji.html?parmas=' +
      encodeURIComponent(
        JSON.stringify({
          id: '滑翔伞2',
          name: '滑翔伞'
        })
      ),
    assetPath: '/JC_CustomAssets/ObjectLibrary/Exhibition/滑翔伞/滑翔伞带人',
    groupId1: 'HuaObjectDaGroup',
    groupId2: 'HuaObjectDaMarker'
  }
]

/**
 * 添加线
 * @param {Array} List
 * @param {String} color 颜色
 */
export const addLine = (List, color) => {
  let pList = []
  List.forEach((item) => {
    const coor = item.coor.map((item) => {
      return [item[0], item[1], item[2]]
    })
    let p1 = {
      id: item.name, //折线唯一标识id
      coordinates: coor, //构成折线的坐标点数组
      coordinateType: 0, //坐标系类型，取值范围：0为Projection类型，1为WGS84类型，2为火星坐标系(GCJ02)，3为百度坐标系(BD09)，默认值：0
      range: [1, 10000000], //可视范围：[近裁距离, 远裁距离]，取值范围: [任意负值, 任意正值]
      color: color, //折线颜色
      thickness: 500, //折线宽度
      intensity: 0.8, //亮度
      flowRate: 0.5, //流速
      shape: 0, //折线类型 0：直线， 1：曲线
      depthTest: true, //是否做深度检测 开启后会被地形高度遮挡
      style: 1, //折线样式 参考样式枚举：PolylineStyle
      tiling: 0 //材质贴图平铺比例
    }
    pList.push(p1)
  })
  __g.polyline.add(pList)
}

/**
 * 点击出现弹框
 * @param e
 */
export const showDialog = async (e) => {
  if (
    e.GroupID === 'CusObjectDaMarker' ||
    e.GroupID === 'EvtolObjectDaMarker' ||
    (e.GroupID === 'HuaObjectDaMarker' && e.Type === 'marker')
  ) {
    clearInterval(window.timer)
    __g.polyline.setThickness(e.Id, -1)
    __g.customObject.focus(e.Id, -1)
    return
  }
}

/**
 * 添加飞行器
 */
export const addCusObjectDa = async (List) => {
  let pList = []
  let pList1 = []
  List.forEach(async (item, index) => {
    item.coor.forEach(async (it, i) => {
      if (i === 0) {
        let o = {
          id: item.id, //自定义对象唯一id
          pakFilePath: '@path:DTS_Library.pak',
          assetPath: item.assetPath,
          location: it, //位置坐标
          coordinateType: 0, // 坐标系类型
          rotation: [0, 0, 0], // 世界坐标系旋转
          range: [0, 10000000], //可见范围
          groupId: item.groupId1, //分组id
          localRotation: [0, item.jd, 0], //模型自身旋转
          scale: [1, 1, 1], //模型缩放
          isEffectRotation: true, //是否开启旋转效果
          smoothMotion: 1, //1: 平滑移动，0: 跳跃移动
          supportAttach: false, //不支持贴画贴合
          visible: true, //模型加载后默认是否显示
          autoHeight: false //是否开启自动高度 开启后自动贴地不再使用坐标Z
        }
        pList.push(o)
        let o1 = {
          id: item.id, //maker唯一标识
          groupId: item.groupId2,
          coordinate: it, //坐标位置
          coordinateType: 0, //坐标系类型
          imagePath: item.imagePath, //图片路径
          anchors: [-25, 50],
          imageSize: [50, 50],
          fixedSize: true,
          text: '',
          fontColor: '#ffffff',
          fontSize: 12,
          textRange: [1, 2000000000],
          textBackgroundColor: '#008214',
          range: [1, 2000000000], //标签的可见范围 [Min,Max]
          autoHidePopupWindow: true,
          autoHeight: false,
          occlusionCull: false,
          popupURL: item.popupURL, //弹窗HTML链接
          // popupBackgroundColor: [1.0, 1.0, 1.0, 0.5],//弹窗背景颜色
          popupSize: [250, 180], //弹窗大小
          popupOffset: [-130, -100], //弹窗偏移
          showLine: false, //标注点下方是否显示垂直牵引线
          displayMode: 4, //智能显示模式  开发过程中请根据业务需求判断使用四种显示模式
          clusterByImage: true, // 聚合时是否根据图片路径分类，即当多个marker的imagePath路径参数相同时按路径对marker分类聚合
          priority: 0 //避让优先级
        }
        pList1.push(o1)
      }
    })
  })
  __g.customObject.add(pList)
  __g.marker.add(pList1)

  pList.forEach(async (item) => {
    __g.customObject.callBPFunction([
      {
        id: item.id,
        functionName: '状态',
        parameters: [
          { paramType: 0, paramValue: 1 },
          { paramType: 3, paramValue: 2 }
        ]
      }
    ])
    __g.marker.setAttachCustomObject([
      {
        markerId: item.id, //标注id
        objectId: item.id, //自定义对象id
        offset: [0, item.id.includes('evtol') ? -0.05 : 0, item.id.includes('evtol') ? 0.5 : 2] //偏移量
      }
    ])
  })
}

//更新标签内容
function random(m, n) {
  return Number(m + Math.random() * (n - m)).toFixed(1)
}

export const updateMarkerText = () => {
  if (window.timer) {
    clearInterval(window.timer)
  }
  window.timer = null
  window.timer = setInterval(() => {
    // __g.marker.update({
    //   id: 'evtol1',
    //   text: `类型：eVTOL\n高度：${random(50, 70)}m\n速度：${random(6, 10)}m/s`
    // })
    // __g.marker.update({
    //   id: 'evtol2',
    //   text: `类型：eVTOL\n高度：${random(50, 70)}m\n速度：${random(6, 10)}m/s`
    // })

    const eVTOLs = [...enList, ...ppList]
    eVTOLs.forEach((item) => {
      __g.marker.update({
        id: item.id,
        textBackgroundColor: '#008214',
        text: `类型：无人机\n高度：${random(50, 70)}m\n速度：${random(6, 10)}m/s`
      })
    })

    //直升机模块
    const zsjs = [...peopleList, ...sList]
    zsjs.forEach((item) => {
      __g.marker.update({
        id: item.id,
        textBackgroundColor: '#4c5676',
        text: `类型：直升机\n高度：${random(300, 600)}m\n速度：${random(30, 40)}m/s`
      })
    })
    const hxs = [...pList]
    hxs.forEach((item) => {
      __g.marker.update({
        id: item.id,
        textBackgroundColor: '#394838',
        text: `类型：滑翔伞\n高度：${random(100, 300)}m\n速度：${random(10, 20)}m/s`
      })
    })

    // 无人机
    const navListxp = [...navList, ...navList2]
    navListxp.forEach((item) => {
      // debugger
      __g.marker.update({
        id: item.id,
        textBackgroundColor: '#394838',
        text: `类型：无人机\n高度：${random(100, 300)}m\n速度：${random(10, 20)}m/s`
      })
    })

    // 民航客机
    const mhkjxp = [...mhkj, ...mhkj2]
    mhkjxp.forEach((item) => {
      __g.marker.update({
        id: item.id,
        textBackgroundColor: '#394838',
        text: `类型：民航客机\n高度：${random(100, 300)}m\n速度：${random(10, 20)}m/s`
      })
    })




  }, 2000)
}

// 取消计时器
export const clearTimer = () => {
  clearInterval(window.timer)
}

/**
 * 飞行器行走
 * @param List 列表
 * @param speedPeople 速度
 */
export const cusObjectDaMove = async (List, speedPeople = 40) => {
  List.forEach((item, index) => {
    //构造移动路径点数组
    let pathPointArr = []
    let sum = 0
    for (let i = 0; i < item.coor.length - 1; i++) {
      //构造数组元素 每1秒移动一次
      let elementPoint = { time: sum, coordinate: item.coor[i] }
      pathPointArr.push(elementPoint)
      sum += computedDistance(item.coor[i], item.coor[i + 1]) / speedPeople
    }
    // 最后一项
    let elementPoint = {
      time: sum + (sum / item.coor.length - 1),
      coordinate: item.coor[item.coor.length - 1]
    }
    pathPointArr.push(elementPoint)

    //车辆按GPS轨迹移动
    __g.customObject.startMove(List[index].id, 0, pathPointArr)
    // __g.customObject.focus(peopleList[0].id)
  })
}

/**
 * 车辆坐标
 */
const carList = [
  {
    id: 'car1',
    coor: [
      [510227.514375, 2497957.44, 45.8420703125],
      [510192.236875, 2497760.48, 39.10033203125],
      [510175.5175, 2497647.04, 32.7070703125],
      [510155.93312500004, 2497540.64, 29.997167968750002]
    ],
    jd: 90,
    name: '车辆1'
  },
  {
    id: 'car2',
    coor: [
      [510155.14187500003, 2497797.44, 49.152109375],
      [510118.31, 2497725.6, 47.242265625],
      [510102.989375, 2497617.2800000003, 35.0228515625],
      [510104.638125, 2497570.72, 33.7860546875]
    ],
    jd: 90,
    name: '车辆2'
  }
]

/**
 * 添加车辆
 */
export const addCar = async () => {
  let pList = []
  carList.forEach((item) => {
    item.coor.forEach(async (it, i) => {
      if (i === 0) {
        let vc1 = {
          id: item.id,
          coordinateType: 0,
          coordinate: it, //
          assetPath: '/JC_CustomAssets/ObjectLibrary/Exhibition/交通工具/工程车/工程车_2', //资源库车辆路径
          rotation: [0, item.jd, 0],
          colorType: 0, //0: 使用随机涂装颜色  大于0的正整数: 使用固定涂装颜色
          color: [1, 1, 0, 1], // 开启自定义颜色 则会覆盖colorType涂装颜色
          autoHeight: true, //开启自动高度 贴地移动
          delay: 1, //控制载具moveTo()接口移动的延迟时间 单位：秒
          useInitZ: false, //是否使用添加载具初始化坐标的高度Z
          localOffset: [0, 0, 0],
          supportAttach: true,
          visible: true //默认可见性
        }
        pList.push(vc1)
      }
    })
  })
  __g.vehicle.add(pList)
}

/**
 * 定于车移动的速度
 */
const speedCar = 5

/**
 * 车行走
 */
export const carMove = async () => {
  carList.forEach((item) => {
    //构造移动路径点数组
    let pathPointArr = []
    let sum = 0
    for (let i = 0; i < item.coor.length - 1; i++) {
      //构造数组元素 每1秒移动一次
      let elementPoint = { coordinate: item.coor[i], gear: 3, timeStamp: sum }
      pathPointArr.push(elementPoint)
      sum += computedDistance(item.coor[i], item.coor[i + 1]) / speedCar
    }
    // 最后一项
    let elementPoint = {
      coordinate: item.coor[item.coor.length - 1],
      gear: 3,
      timeStamp: sum + (sum / item.coor.length - 1)
    }
    pathPointArr.push(elementPoint)

    let wayPoints = [
      {
        id: item.id,
        wayPoints: pathPointArr
      }
    ]

    __g.vehicle.setWayPoint(wayPoints)
    //车辆按GPS轨迹移动
    __g.vehicle.start([
      {
        id: item.id,
        timeStamp: 0 //设置载具v1从wayPoints的第0秒开始运动
      }
    ])
  })
  //设置相机自动跟随
  __g.vehicle.focus(carList[0].id)
}

// const dialogStore = useDialogStore()

/**
 * 关闭弹窗
 */
// export const closePeopleDialog = () => {
//     dialogStore.setDialogVisible(false)
// }

/**
 * 清除
 */
export const clear = async () => {
  __g.customObject.clear()
  __g.marker.clear()
  __g.polyline.clear()
  // await __g.vehicle.clear()
}

/**
 * 计算投影坐标中空间两点的距离
 */
const computedDistance = (coord1, coord2) => {
  const [x1, y1, z1] = coord1
  const [x2, y2, z2] = coord2

  const deltaX = x2 - x1
  const deltaY = y2 - y1
  const deltaZ = z2 - z1

  const distance = Math.sqrt(deltaX ** 2 + deltaY ** 2 + deltaZ ** 2)
  return distance
}
